<template>
<!--  <a class="mr-14" @click="getDataSpaceFile(item)" v-for="(item,index) in CurriculumDataList">{{ item.name }}</a>-->
  <el-row class="grid justify-items-center">
    <el-card class="box-card w-7/12 mt-10">
      <template #header>
        <div class="card-header">
          <span>课程附件</span>
        </div>
      </template>
      <a class="mr-14 item text" v-for="(item,index) in CurriculumDataList" :download="getNameFromUrl(item.url)" :href="'/api/GetDataSpaceFileByUrl?url='+item.url+'&tk='+fileUpHead.tk">{{ item.name }}</a>

    </el-card>
<!--    <a class="mr-14" v-for="(item,index) in CurriculumDataList" :download="getNameFromUrl(item.url)" :href="'/api/GetDataSpaceFileByUrl?url='+item.url+'&tk='+fileUpHead.tk">{{ item.name }}</a>-->
  </el-row>
  <el-row class="grid justify-items-center mt-10">

<!--    <div class="block">-->
<!--      <el-timeline>-->
<!--        <el-timeline-item v-for="(item,index) in ChapterList" center timestamp="2018/4/12" placement="top">-->
<!--          <el-card>-->
<!--            <h4>{{ item.ChapterName }}</h4>-->
<!--            <p>{{ item.ChapterDescribe }}</p>-->
<!--            <a class="mr-14" v-for="(dataItem,index) in item.ChapterDataList" :download="getNameFromUrl(dataItem.url)" :href="'/api/GetDataSpaceFileByUrl?url='+dataItem.url+'&tk='+fileUpHead.tk">{{ dataItem.name }}</a>-->

<!--          </el-card>-->
<!--        </el-timeline-item>-->
<!--      </el-timeline>-->
<!--    </div>-->
    <el-collapse class="w-9/12">
      <el-collapse-item v-for="(item,index) in ChapterList" :title="item.ChapterName" :name="index">
        <div>
          {{item.ChapterDescribe}}
          </div>
        <el-row>
          <a class="mr-14" v-for="(dataItem,index) in item.ChapterDataList" :download="getNameFromUrl(dataItem.url)" :href="'/api/GetDataSpaceFileByUrl?url='+dataItem.url+'&tk='+fileUpHead.tk">{{ dataItem.name }}</a>

        </el-row>
      </el-collapse-item>
    </el-collapse>
  </el-row>

</template>

<script>
import axios from "axios";

export default {
  name: "CurriculumDetail",
  created() {
    var parse = JSON.parse(window.localStorage.getItem('zjxClass_student_info'));
    this.fileUpHead = {
      'tk': parse.Token
    }

    this.CurriculumInfo = this.$sestor.getSesWithParse(this.$route.query.resId)
    console.log(this.CurriculumInfo)
    axios.post("/api/GetChapterByCurriculum", {
      id: this.CurriculumInfo.ID
    }).then((res) => {
      if (res.status === 200) {
        this.ChapterList = res.data
        for (let i = 0; i < this.ChapterList.length; i++) {
          axios.post("/api/GetFileList", {
            IdList: this.ChapterList[i].ChapterData
          }).then((res) => {
            if (res.status === 200) {
              this.ChapterList[i].ChapterDataList = res.data
            }
          })
        }
      }
    })

    axios.post("/api/GetFileList", {
      IdList: this.CurriculumInfo.CurriculumData
    }).then((res) => {
      if (res.status === 200) {
        this.CurriculumDataList = res.data
      }
    })


  },
  mounted() {
    console.log(this.ChapterList)

  },
  data() {
    return {
      CurriculumDataList: [],
      ChapterList: [],
      CurriculumInfo: {},
      fileUpHead:{}
    }
  },
  methods: {
    getNameFromUrl(item){
      return item.split("_zjx_")[1]
    },
  }
}
</script>

<style scoped>

</style>